<template>
  <div class="container">
    <!-- <img class="return" src="../assets/back.png" alt="" @click="linkToBack" v-if="!isShowIframe" /> -->

    <div v-if="!isShowIframe" @click="linkToBack" class="return">主页</div>

    <div v-if="!isShowIframe">
      <div class="btn_item" v-for="item in btnsList" :key="item.id" @click="linkToUrl(item.url)"></div>
    </div>

    <template v-if="isShowIframe">
      <!-- <iframe :src="frameUrl" style="width: 100%; height: 100vh"></iframe> -->

      <webview id="myWebView" :src="frameUrl" style="width: 100%; height: 100vh"></webview>

      <div class="float-button">
        <div class="btn-home" @click="jumpHomePage">主页</div>
        <div class="btn-back" @click="jumpBack">返回</div>
      </div>
    </template>
  </div>
</template>

<script setup>
import { useRouter } from "vue-router";
import { nextTick, ref } from "vue";
const btnsList = ref([
  {
    id: "0",
    url: "https://www.dkshdiscover.com.cn/formulations-lib/14",
  },
  {
    id: "1",
    url: "https://www.dkshdiscover.com.cn/formulations-lib/15",
  },
  {
    id: "2",
    url: "https://www.dkshdiscover.com.cn/formulations-lib/16",
  },
  {
    id: "3",
    url: "https://www.dkshdiscover.com.cn/formulations-lib/18",
  },
  {
    id: "4",
    url: "https://www.dkshdiscover.com.cn/formulations-lib/17",
  },
  {
    id: "5",
    url: "https://www.dkshdiscover.com.cn/formulations-lib/20",
  },
  {
    id: "6",
    url: "https://www.dkshdiscover.com.cn/formulations-lib/19",
  },
]);
const isShowIframe = ref(false);
const frameUrl = ref("");
const router = useRouter();
const linkToBack = () => {
  router.go(-1);
};

const jumpHomePage = () => {
  isShowIframe.value = false;
  frameUrl.value = "";
  router.replace("/home");
};

const jumpBack = () => {
  isShowIframe.value = false;
  frameUrl.value = "";
};

const linkToUrl = (url) => {
  console.log("url", url);
  frameUrl.value = url;
  isShowIframe.value = true;
};
</script>

<style scoped>
.container {
  background: url("../assets/protect.jpg");
  background-origin: 100% 100%;
  background-size: contain;
  width: 100%;
  /* height: 100vh;
  overflow: hidden; */
  aspect-ratio: 9/16;
  position: relative;
}

.return {
  position: absolute;
  bottom: 5%;
  left: 7%;
  width: 8vw;
  height: 4vw;
  padding: 2vw 3vw;
  display: flex;
  align-items: center;
  background-color: red;
  color: white;
  justify-content: center;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.btn_item {
  position: absolute;
  width: 17vw;
  height: 17vw;
  cursor: pointer;
  /* background: pink; */
  border-radius: 50%;
  margin-bottom: 2.8%;
}

.btn_item:nth-child(1) {
  top: 14%;
  left: 36%;
}

.btn_item:nth-child(2) {
  top: 19.5%;
  left: 16%;
}

.btn_item:nth-child(3) {
  top: 29.5%;
  left: 8%;
}

.btn_item:nth-child(4) {
  top: 40%;
  left: 11%;
}

.btn_item:nth-child(5) {
  top: 50%;
  left: 20%;
}

.btn_item:nth-child(6) {
  top: 68.5%;
  right: 13%;
  width: 30%;
  height: 6%;
  border-radius: 0;
}

.btn_item:nth-child(7) {
  top: 76.5%;
  right: 13%;
  width: 30%;
  height: 6%;
  border-radius: 0;
}

.float-button {
  z-index: 999;
  position: fixed;
  bottom: 5%;
  left: 3%;
  user-select: none;
  display: flex;
  flex-wrap: nowrap;
}

.btn-home,
.btn-back {
  background-color: red;
  color: white;
  width: 8vw;
  height: 4vw;
  padding: 2vw 3vw;
  text-align: center;
  border-radius: 4px;
  /* font-size: 4vw; */
  line-height: 4vw;
  border: none;
  box-shadow: 0 0 1vw 0.4vw rgba(214, 18, 18, 0.4);
  margin-bottom: 6vw;
  cursor: pointer;
}

.btn-back {
  margin-left: 2vw;
}

webview {
  background: #FFFFFF;
  position: absolute;
  width: 100%;
  height: 100vh;
  /* z-index: 999; */
}
</style>
